//
//  DetailViewController.m
//  helloword
//
//  Created by chen on 17/3/8.
//  Copyright © 2017年 chen. All rights reserved.
//

#import "DetailViewController.h"
#import "WebKit/WebKit.h"

@interface DetailViewController ()<WKNavigationDelegate>

@property(strong,nonatomic) WKWebView *webView;
@end

@implementation DetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加WKwebView
    self.webView = [[WKWebView alloc]initWithFrame:self.view.frame];
    [self.view addSubview:_webView];
    self.webView.navigationDelegate = self;
    //test
//    NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
//    NSURL *bundleUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
//    NSData *htmlData = [[NSData alloc] initWithContentsOfFile:htmlPath];
//    [self.webView loadData:htmlData MIMEType:@"text/html" characterEncodingName:@"UTF-8" baseURL:bundleUrl];
    //test1
//    NSURL *url = [NSURL URLWithString:@"http://www.51work6.com"];
//    NSURLRequest *request = [NSURLRequest requestWithURL:url];
//    [self.webView loadRequest:request];
    //访问地址
    NSString *urlPath = [NSString stringWithFormat:@"http://baike.baidu.com/item/%@",_address];
    NSString *urlP = @"http://baike.baidu.com";
    NSURL *url = [NSURL URLWithString:urlP];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [_webView loadRequest:request];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark -- 实现WKNavigationDelegate委托协议
- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation{
    NSLog(@"开始加载");
}
-(void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation{
    NSLog(@"内容开始返回");
}
-(void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation{
    NSLog(@"加载完成");
}
-(void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error{
    NSLog(@"加载失败error:%@",error);
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
